﻿namespace SERFLITEMAX20.DataView
{
    using SERFLITEMAX20;
    using SERFLITEMAX20.DataObjects;
    using SERFLITEMAX20.WinUI.Controls;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class frmMain : Form
    {
        private Button button1;
        private ToolStripMenuItem chestToolStripMenuItem;
        private ToolStripMenuItem clearFilteredToolStripMenuItem;
        private ToolStripMenuItem clearSpecialToolStripMenuItem;
        private ToolStripMenuItem clearToolStripMenuItem;
        private ColumnHeader columnHeader1;
        private ColumnHeader columnHeader2;
        private ColumnHeader columnHeader3;
        private ColumnHeader columnHeader4;
        private ColumnHeader columnHeader5;
        private ColumnHeader columnHeader6;
        private ComboBox comboBox1;
        private IContainer components = null;
        private ContextMenuStrip contextMenuStrip1;
        private GameObjects gameObjects = GameObjects.Load();
        private ToolStripMenuItem herbToolStripMenuItem;
        private SortedList<int, GameObject> ignorelist = new SortedList<int, GameObject>();
        private ListViewSortManager listViewSortManager = null;
        private ListView lstView;
        private ToolStripMenuItem mineralToolStripMenuItem;
        private ToolStripMenuItem setFilteredToolStripMenuItem;
        private ToolStripMenuItem setSpecialToolStripMenuItem;
        private ToolStripMenuItem setSubtypeToolStripMenuItem;

        public frmMain()
        {
            this.InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.gameObjects.Save();
        }

        private void chestToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.lstView.SelectedItems)
            {
                GameObject tag = (GameObject) item.Tag;
                tag.subtype = 3;
                item.SubItems[1].Text = enNodeType.Chest.ToString();
            }
        }

        private void clearFilteredToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.lstView.SelectedItems)
            {
                GameObject tag = (GameObject) item.Tag;
                tag.filtered = false;
                item.SubItems[4].Text = "false";
                item.BackColor = Color.White;
            }
        }

        private void clearSpecialToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.lstView.SelectedItems)
            {
                GameObject tag = (GameObject) item.Tag;
                tag.special = false;
                item.SubItems[5].Text = "false";
                item.ForeColor = Color.Black;
            }
        }

        private void clearToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.lstView.SelectedItems)
            {
                GameObject tag = (GameObject) item.Tag;
                tag.subtype = -1;
                item.SubItems[1].Text = enNodeType.None.ToString();
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.lstView.Items.Clear();
            this.lstView.ListViewItemSorter = null;
            foreach (GameObject obj2 in this.gameObjects.GameObjectItemsArray)
            {
                if (this.comboBox1.Text == ((GameobjectTypes) obj2.typeid).ToString())
                {
                    ListViewItem item = this.lstView.Items.Add(obj2.entry.ToString());
                    item.SubItems.Add(((enNodeType) obj2.subtype).ToString());
                    item.SubItems.Add(((GameobjectTypes) obj2.typeid).ToString());
                    item.SubItems.Add(obj2.name);
                    item.SubItems.Add(obj2.filtered.ToString());
                    item.SubItems.Add(obj2.special.ToString());
                    item.Tag = obj2;
                    if (obj2.filtered)
                    {
                        item.BackColor = Color.LightGray;
                    }
                    if (obj2.special)
                    {
                        item.ForeColor = Color.Red;
                    }
                }
            }
            for (int i = 0; i < this.lstView.Columns.Count; i++)
            {
                this.lstView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            }
            this.listViewSortManager = new ListViewSortManager(this.lstView, new System.Type[] { typeof(ListViewInt32Sort), typeof(ListViewTextSort), typeof(ListViewTextSort), typeof(ListViewTextSort), typeof(ListViewTextSort), typeof(ListViewTextSort) });
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void fishholeToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            for (int i = 0; i <= 0x23; i++)
            {
                this.comboBox1.Items.Add(((GameobjectTypes) i).ToString());
            }
        }

        private void herbToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.lstView.SelectedItems)
            {
                GameObject tag = (GameObject) item.Tag;
                tag.subtype = 2;
                item.SubItems[1].Text = enNodeType.Herb.ToString();
            }
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.lstView = new System.Windows.Forms.ListView();
            this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.setFilteredToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.clearFilteredToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.setSubtypeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.herbToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.chestToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.mineralToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.clearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.setSpecialToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.clearSpecialToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.button1 = new System.Windows.Forms.Button();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.contextMenuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // lstView
            // 
            this.lstView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lstView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader1,
            this.columnHeader5,
            this.columnHeader2,
            this.columnHeader3,
            this.columnHeader4,
            this.columnHeader6});
            this.lstView.ContextMenuStrip = this.contextMenuStrip1;
            this.lstView.FullRowSelect = true;
            this.lstView.HideSelection = false;
            this.lstView.Location = new System.Drawing.Point(0, 39);
            this.lstView.Name = "lstView";
            this.lstView.Size = new System.Drawing.Size(640, 347);
            this.lstView.TabIndex = 0;
            this.lstView.UseCompatibleStateImageBehavior = false;
            this.lstView.View = System.Windows.Forms.View.Details;
            // 
            // columnHeader1
            // 
            this.columnHeader1.Text = "entry";
            // 
            // columnHeader5
            // 
            this.columnHeader5.Text = "subtype";
            // 
            // columnHeader2
            // 
            this.columnHeader2.Text = "typeid";
            // 
            // columnHeader3
            // 
            this.columnHeader3.Text = "name";
            // 
            // columnHeader4
            // 
            this.columnHeader4.Text = "filtered";
            // 
            // columnHeader6
            // 
            this.columnHeader6.Text = "special";
            // 
            // contextMenuStrip1
            // 
            this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.setFilteredToolStripMenuItem,
            this.clearFilteredToolStripMenuItem,
            this.setSubtypeToolStripMenuItem,
            this.setSpecialToolStripMenuItem,
            this.clearSpecialToolStripMenuItem});
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(146, 114);
            // 
            // setFilteredToolStripMenuItem
            // 
            this.setFilteredToolStripMenuItem.Name = "setFilteredToolStripMenuItem";
            this.setFilteredToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
            this.setFilteredToolStripMenuItem.Text = "set filtered";
            this.setFilteredToolStripMenuItem.Click += new System.EventHandler(this.setFilteredToolStripMenuItem_Click);
            // 
            // clearFilteredToolStripMenuItem
            // 
            this.clearFilteredToolStripMenuItem.Name = "clearFilteredToolStripMenuItem";
            this.clearFilteredToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
            this.clearFilteredToolStripMenuItem.Text = "clear filtered";
            this.clearFilteredToolStripMenuItem.Click += new System.EventHandler(this.clearFilteredToolStripMenuItem_Click);
            // 
            // setSubtypeToolStripMenuItem
            // 
            this.setSubtypeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.herbToolStripMenuItem,
            this.chestToolStripMenuItem,
            this.mineralToolStripMenuItem,
            this.clearToolStripMenuItem});
            this.setSubtypeToolStripMenuItem.Name = "setSubtypeToolStripMenuItem";
            this.setSubtypeToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
            this.setSubtypeToolStripMenuItem.Text = "set subtype";
            // 
            // herbToolStripMenuItem
            // 
            this.herbToolStripMenuItem.Name = "herbToolStripMenuItem";
            this.herbToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
            this.herbToolStripMenuItem.Text = "herb";
            this.herbToolStripMenuItem.Click += new System.EventHandler(this.herbToolStripMenuItem_Click);
            // 
            // chestToolStripMenuItem
            // 
            this.chestToolStripMenuItem.Name = "chestToolStripMenuItem";
            this.chestToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
            this.chestToolStripMenuItem.Text = "chest";
            this.chestToolStripMenuItem.Click += new System.EventHandler(this.chestToolStripMenuItem_Click);
            // 
            // mineralToolStripMenuItem
            // 
            this.mineralToolStripMenuItem.Name = "mineralToolStripMenuItem";
            this.mineralToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
            this.mineralToolStripMenuItem.Text = "mineral";
            this.mineralToolStripMenuItem.Click += new System.EventHandler(this.mineralToolStripMenuItem_Click);
            // 
            // clearToolStripMenuItem
            // 
            this.clearToolStripMenuItem.Name = "clearToolStripMenuItem";
            this.clearToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
            this.clearToolStripMenuItem.Text = "clear";
            this.clearToolStripMenuItem.Click += new System.EventHandler(this.clearToolStripMenuItem_Click);
            // 
            // setSpecialToolStripMenuItem
            // 
            this.setSpecialToolStripMenuItem.Name = "setSpecialToolStripMenuItem";
            this.setSpecialToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
            this.setSpecialToolStripMenuItem.Text = "set special";
            this.setSpecialToolStripMenuItem.Click += new System.EventHandler(this.setSpecialToolStripMenuItem_Click);
            // 
            // clearSpecialToolStripMenuItem
            // 
            this.clearSpecialToolStripMenuItem.Name = "clearSpecialToolStripMenuItem";
            this.clearSpecialToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
            this.clearSpecialToolStripMenuItem.Text = "clear special";
            this.clearSpecialToolStripMenuItem.Click += new System.EventHandler(this.clearSpecialToolStripMenuItem_Click);
            // 
            // button1
            // 
            this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.button1.Location = new System.Drawing.Point(336, 12);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(66, 22);
            this.button1.TabIndex = 2;
            this.button1.Text = "Save";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // comboBox1
            // 
            this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Location = new System.Drawing.Point(408, 12);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(230, 21);
            this.comboBox1.TabIndex = 1;
            this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
            // 
            // frmMain
            // 
            this.ClientSize = new System.Drawing.Size(640, 386);
            this.Controls.Add(this.comboBox1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.lstView);
            this.Name = "frmMain";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.frmMain_Load);
            this.contextMenuStrip1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        private void mineralToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.lstView.SelectedItems)
            {
                GameObject tag = (GameObject) item.Tag;
                tag.subtype = 1;
                item.SubItems[1].Text = enNodeType.Mine.ToString();
            }
        }

        private void setFilteredToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.lstView.SelectedItems)
            {
                GameObject tag = (GameObject) item.Tag;
                tag.filtered = true;
                item.SubItems[4].Text = "true";
                item.BackColor = Color.LightGray;
            }
        }

        private void setSpecialToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.lstView.SelectedItems)
            {
                GameObject tag = (GameObject) item.Tag;
                tag.special = true;
                item.SubItems[5].Text = "true";
                item.ForeColor = Color.Red;
            }
        }
    }
}

